package com.example.demo.ImgTest;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class VideoTest {

    public static void main(String[] args) {

        String videoPath = "C:/Users/FF998/Pictures/Camera Roll/58c34c248ccb9e4a3703385813e273f2.mp4";
        try {
            ProcessBuilder processBuilder = new ProcessBuilder("ffmpeg", "-i", videoPath);
            Process process = processBuilder.start();

            BufferedReader reader = new BufferedReader(new InputStreamReader(process.getErrorStream()));
            String line;

            while ((line = reader.readLine()) != null) {
                if (line.contains("Duration")) {
                    System.out.println(line);
                    System.out.println("------------------");
                    String duration = line.substring(line.indexOf(":") + 2, line.indexOf(","));
                    System.out.println("视频时长：" + duration);
                }
            }
            reader.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

}
